﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace AsteroidWar
{
    class Button
    {
        public string name;
        Vector2 position;
        Texture2D texture;
        int width = 300;
        int height = 60;
        Rectangle boundingBox;
        public bool isClicked= false;
        Color color = new Color(255, 255, 255, 255);
        bool downColor;

        public Button(string name, Texture2D texture, Vector2 position)
        {
            this.name = name;
            this.texture = texture;
            this.position = position;
            this.boundingBox = new Rectangle((int)position.X, (int)position.Y,
                width, height);
        }

        public void setSize(int width, int height)
        {
            this.width = width;
            this.height = height;
            this.boundingBox = new Rectangle((int)position.X, (int)position.Y,
                width, height);
        }

        public void Update(MouseState mouse)
        {

            Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);

            if (mouseRectangle.Intersects(boundingBox))
            {
                if (color.A == 255) downColor = false;
                if (color.A <= 180) downColor = true;

                if (downColor) color.A += 2;
                else if (color.A > 180 && !downColor)
                {
                    color.A -= 2;
                }
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    isClicked = true;
                }
            }
            else if (color.A < 255)
            {
                color.A += 2;
                isClicked = false;
            }
        }

        public void setPosition(Vector2 newPosition)
        {
            position = newPosition;
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, boundingBox, color);
        }

    }
}
